﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Derbster.Domain.Test
{
    [TestClass]
    public class JamScoringUnitTest : ContractUnitTest
    {
        private Match _testMatch;
        private CommandManager _commandManager;

        [TestInitialize]
        public void TestSetup()
        {
            _testMatch = TestHelper.CreateTestMatch(true, true, "TestMatch");
            _commandManager = new CommandManager();
            _commandManager.Clear();
        }

        [TestMethod]
        public void TestFirstLeadAndScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _commandManager.Undo();
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _commandManager.Redo();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _testMatch.CurrentJam.FirstTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
        }

        [TestMethod]
        public void TestSecondLeadAndScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _commandManager.Undo();
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _commandManager.Redo();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _testMatch.CurrentJam.SecondTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
        }

        [TestMethod]
        public void TestFirstBadScore()
        {
            bool throws = false;

            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            try
            {
                _testMatch.CurrentJam.FirstTeamScore(7);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestFirstBadScoreTwo()
        {
            bool throws = false;

            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            try
            {
                _testMatch.CurrentJam.FirstTeamScore(-1);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestSecondBadScore()
        {
            bool throws = false;

            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            try
            {
                _testMatch.CurrentJam.SecondTeamScore(7);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }
        [TestMethod]
        public void TestSecondBadScoreTwo()
        {
            bool throws = false;

            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            try
            {
                _testMatch.CurrentJam.SecondTeamScore(-7);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestFirstLeadAndTwoScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            _testMatch.CurrentJam.FirstTeamScore(4);
            _testMatch.CurrentJam.FirstTeamScore(5);
            Assert.AreEqual(2, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(9, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(2, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(9, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
        }

        [TestMethod]
        public void TestSecondLeadAndTwoScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            _testMatch.CurrentJam.SecondTeamScore(4);
            _testMatch.CurrentJam.SecondTeamScore(5);
            Assert.AreEqual(2, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(9, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(2, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(9, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
        }

        [TestMethod]
        public void TestFirstLeadAndLost()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _testMatch.CurrentJam.FirstTeamLostLead();
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.Lost);
            _commandManager.Undo();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.Lost);
            _commandManager.Redo();
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.Lost);

        }

        [TestMethod]
        public void TestSecondLeadAndLost()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _testMatch.CurrentJam.SecondTeamLostLead();
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.Lost);
            _commandManager.Undo();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.Lost);
            _commandManager.Redo();
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.Lost);
        }

        [TestMethod]
        public void TestFirstLeadAndCorrectScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _testMatch.CurrentJam.FirstTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _testMatch.CurrentJam.CorrectFirstTeamScore(1, 5);
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(5, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(5, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
        }

       


        [TestMethod]
        public void TestSecondLeadAndCorrectScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _testMatch.CurrentJam.SecondTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _testMatch.CurrentJam.CorrectSecondTeamScore(1, 5);
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(5, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(5, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
        }

        [TestMethod]
        public void TestFirstLeadAndCorrectBadScore()
        {
            bool throws = false;
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _testMatch.CurrentJam.FirstTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            try
            {
                _testMatch.CurrentJam.CorrectFirstTeamScore(1, 7);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestSecondLeadAndCorrectBadScore()
        {
            bool throws = false;
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _testMatch.CurrentJam.SecondTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            try
            {
                _testMatch.CurrentJam.CorrectSecondTeamScore(1, 7);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestFirstLeadAndCorrectBadScoreTwo()
        {
            bool throws = false;
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _testMatch.CurrentJam.FirstTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            try
            {
                _testMatch.CurrentJam.CorrectFirstTeamScore(1, -7);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestSecondLeadAndCorrectBadScoreTwo()
        {
            bool throws = false;
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _testMatch.CurrentJam.SecondTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            try
            {
                _testMatch.CurrentJam.CorrectSecondTeamScore(1, -7);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestFirstLeadAndRemoveScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.IsLead);
            _testMatch.CurrentJam.FirstTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _testMatch.CurrentJam.RemoveFirstTeamScoringPass();
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(1, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.FirstTeamScoring.Sum(sp => sp.Score));
        }

        [TestMethod]
        public void TestSecondLeadAndRemoveScore()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.IsLead);
            _testMatch.CurrentJam.SecondTeamScore(4);
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _testMatch.CurrentJam.RemoveSecondTeamScoringPass();
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Undo();
            Assert.AreEqual(1, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(4, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
            _commandManager.Redo();
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Count());
            Assert.AreEqual(0, _testMatch.CurrentJam.SecondTeamScoring.Sum(sp => sp.Score));
        }

        [TestMethod]
        public void TestFirstLeadAndCalled()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            _testMatch.CurrentJam.FirstTeamCalledJam();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
            _commandManager.Undo();
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
            _commandManager.Redo();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
        }

        [TestMethod]
        public void TestSecondLeadAndCalled()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            _testMatch.CurrentJam.SecondTeamCalledJam();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
            _commandManager.Undo();
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
            _commandManager.Redo();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
        }

        [TestMethod]
        public void TestFirstTeamCalledJamInError()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.SecondTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddBlocker(player);
            var player2 = _testMatch.SecondTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.SecondTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.SecondTeamLead();
            _testMatch.CurrentJam.FirstTeamCalledJam();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsTrue(_testMatch.CurrentJam.CalledInError);
            _commandManager.Undo();
            Assert.IsFalse(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
            _commandManager.Redo();
            Assert.IsTrue(_testMatch.CurrentJam.FirstTeamScoring.Called);
            Assert.IsTrue(_testMatch.CurrentJam.CalledInError);
        }
        
        [TestMethod]
        public void TestSecondTeamCalledJamInError()
        {
            _testMatch.BeginMatch();
            _testMatch.BeginPeriod();
            var player = _testMatch.FirstTeamRoster.Players.Skip(1).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddBlocker(player);
            var player2 = _testMatch.FirstTeamRoster.Players.Skip(3).First();
            _testMatch.CurrentJam.FirstTeamLineup.AddJammer(player2);
            _testMatch.BeginJam();
            _testMatch.CurrentJam.FirstTeamLead();
            _testMatch.CurrentJam.SecondTeamCalledJam();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsTrue(_testMatch.CurrentJam.CalledInError);
            _commandManager.Undo();
            Assert.IsFalse(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsFalse(_testMatch.CurrentJam.CalledInError);
            _commandManager.Redo();
            Assert.IsTrue(_testMatch.CurrentJam.SecondTeamScoring.Called);
            Assert.IsTrue(_testMatch.CurrentJam.CalledInError);
        }
    }
}
